# -*- coding:utf-8 -*-
from urllib.request import urlopen      #url操作
from json import load                   #json解析

import myconfig                         #配置类
# url1 = 'https://api.ipify.org'
# url2 = 'http://ip.42.pl/raw'

def get_ip(url_api):
    my_ip = urlopen(url_api).read()        #获取IP
    #print('ip:', my_ip)
    ip_addr = my_ip.decode('utf-8')           #去除b`
    #print(ip_addr)   
    return ip_addr 

def get_dev_ip():
    try:
        ip = get_ip(myconfig.url1)
    except:
        try:
            print('url1 get ip error:404')
            ip = get_ip(myconfig.url2)
        except:
            print('url2 get ip error:404')
        else:
            print('get ip successfully')
    else:        
        print('get ip successfully')

    print(ip)
    return ip


